package com.uyayo.framework.common.constants;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class FileConstants {

	public static final SimpleDateFormat formatYear=new SimpleDateFormat( "yyyy");
	public static final SimpleDateFormat formatMonth=new SimpleDateFormat( "MM");
	public static final  SimpleDateFormat formatDay=new SimpleDateFormat( "dd");

	public static String splitFileDir(String fileDir) {
		fileDir = fileDir + File.separator;
		return fileDir.replaceAll("\\\\", "/");
	}
	
	public static String splitFileDir(String fileDir, String userId) {
		fileDir = fileDir + File.separator + userId + File.separator;
		return fileDir.replaceAll("\\\\", "/");
	}
	
	public static String splitFileDir(String fileDir, Calendar calendar) {
		fileDir = fileDir + File.separator + calendar.get(Calendar.YEAR) + File.separator + calendar.get(Calendar.MONTH)
				+ File.separator + calendar.get(Calendar.DATE) + File.separator;

		return fileDir.replaceAll("\\\\", "/");
	}

	public static String splitFileDirByTime() {
		String fileDir;
		Calendar date=Calendar.getInstance();
		String year=formatYear.format(date.getTime());
		String month=formatMonth.format(date.getTime());
		String day=formatDay.format(date.getTime());
		fileDir =  File.separator + year + File.separator + month + File.separator + day + File.separator;
		return fileDir.replaceAll("\\\\", "/");
	}

	public static String splitFileDirByTime(String fileDir) {

		Calendar date=Calendar.getInstance();
		String year=formatYear.format(date.getTime());
		String month=formatMonth.format(date.getTime());
		String day=formatDay.format(date.getTime());
		fileDir = fileDir + File.separator + year + File.separator + month
				+ File.separator + day + File.separator;
		return fileDir.replaceAll("\\\\", "/");
	}

	public static String splitFileDir(String fileDir, String userId, Calendar calendar) {
		fileDir = fileDir + File.separator + userId + File.separator
				+ calendar.get(Calendar.YEAR) + File.separator + calendar.get(Calendar.MONTH)
				+ File.separator + calendar.get(Calendar.DATE) + File.separator;

		return fileDir.replaceAll("\\\\", "/");
	}
}
